-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang-tidy] Add flag to specify an alternative to std::move in cppcoreguidelines-rvalue-reference-param-not-moved #138757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-tidy] Add flag to specify an alternative to std::move in cppcoreguidelines-rvalue-reference-param-not-moved #138757
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang-tools-extra Author: Dimitrije Dobrota (DimitrijeDobrota) ChangesSince std::move is nothing more than a cast, part of STL and not the language itself, it's easy to provide a custom implementation if one wishes not to include the entirety of <utility>. Added flag (MoveFunction) provides a way to continue using this essential check even with the custom implementation of moving. Since Full diff: https://github.com/llvm/llvm-project/pull/138757.diff 4 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
index 8c386d5bc7945..272152644d7dd 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
@@ -42,9 +42,9 @@ void RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
StatementMatcher MoveCallMatcher =
callExpr(
argumentCountIs(1),
- anyOf(callee(functionDecl(hasName("::std::move"))),
+ anyOf(callee(functionDecl(hasName(MoveFunction))),
callee(unresolvedLookupExpr(hasAnyDeclaration(
- namedDecl(hasUnderlyingDecl(hasName("::std::move"))))))),
+ namedDecl(hasUnderlyingDecl(hasName(MoveFunction))))))),
hasArgument(
0, argumentOf(
AllowPartialMove,
@@ -122,7 +122,8 @@ RvalueReferenceParamNotMovedCheck::RvalueReferenceParamNotMovedCheck(
AllowPartialMove(Options.get("AllowPartialMove", false)),
IgnoreUnnamedParams(Options.get("IgnoreUnnamedParams", false)),
IgnoreNonDeducedTemplateTypes(
- Options.get("IgnoreNonDeducedTemplateTypes", false)) {}
+ Options.get("IgnoreNonDeducedTemplateTypes", false)),
+ MoveFunction(Options.get("MoveFunction", "::std::move")) {}
void RvalueReferenceParamNotMovedCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
@@ -130,6 +131,7 @@ void RvalueReferenceParamNotMovedCheck::storeOptions(
Options.store(Opts, "IgnoreUnnamedParams", IgnoreUnnamedParams);
Options.store(Opts, "IgnoreNonDeducedTemplateTypes",
IgnoreNonDeducedTemplateTypes);
+ Options.store(Opts, "MoveFunction", MoveFunction);
}
} // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
index d8c3d2bd4ba0e..950c0206745d7 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
@@ -32,6 +32,7 @@ class RvalueReferenceParamNotMovedCheck : public ClangTidyCheck {
const bool AllowPartialMove;
const bool IgnoreUnnamedParams;
const bool IgnoreNonDeducedTemplateTypes;
+ const StringRef MoveFunction;
};
} // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 579fca54924d5..82f3bc038c2f2 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -219,6 +219,11 @@ Changes in existing checks
tolerating fix-it breaking compilation when functions is used as pointers
to avoid matching usage of functions within the current compilation unit.
+- Improved :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
+ <clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved>` check
+ by adding a flag to specify the function used for moving instead of
+ ``std::move``.
+
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
index ffa3a9d61e48e..aa2bed9e888a4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
@@ -79,6 +79,11 @@ Options
T other = std::forward<T>(t);
}
+.. option:: MoveFunction
+
+ Specify the function used for moving.
+ Default is `::std::move`.
+
This check implements `F.18
<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f18-for-will-move-from-parameters-pass-by-x-and-stdmove-the-parameter>`_
from the C++ Core Guidelines.
|
|
@llvm/pr-subscribers-clang-tidy Author: Dimitrije Dobrota (DimitrijeDobrota) ChangesSince std::move is nothing more than a cast, part of STL and not the language itself, it's easy to provide a custom implementation if one wishes not to include the entirety of <utility>. Added flag (MoveFunction) provides a way to continue using this essential check even with the custom implementation of moving. Since Full diff: https://github.com/llvm/llvm-project/pull/138757.diff 4 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
index 8c386d5bc7945..272152644d7dd 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
@@ -42,9 +42,9 @@ void RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
StatementMatcher MoveCallMatcher =
callExpr(
argumentCountIs(1),
- anyOf(callee(functionDecl(hasName("::std::move"))),
+ anyOf(callee(functionDecl(hasName(MoveFunction))),
callee(unresolvedLookupExpr(hasAnyDeclaration(
- namedDecl(hasUnderlyingDecl(hasName("::std::move"))))))),
+ namedDecl(hasUnderlyingDecl(hasName(MoveFunction))))))),
hasArgument(
0, argumentOf(
AllowPartialMove,
@@ -122,7 +122,8 @@ RvalueReferenceParamNotMovedCheck::RvalueReferenceParamNotMovedCheck(
AllowPartialMove(Options.get("AllowPartialMove", false)),
IgnoreUnnamedParams(Options.get("IgnoreUnnamedParams", false)),
IgnoreNonDeducedTemplateTypes(
- Options.get("IgnoreNonDeducedTemplateTypes", false)) {}
+ Options.get("IgnoreNonDeducedTemplateTypes", false)),
+ MoveFunction(Options.get("MoveFunction", "::std::move")) {}
void RvalueReferenceParamNotMovedCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
@@ -130,6 +131,7 @@ void RvalueReferenceParamNotMovedCheck::storeOptions(
Options.store(Opts, "IgnoreUnnamedParams", IgnoreUnnamedParams);
Options.store(Opts, "IgnoreNonDeducedTemplateTypes",
IgnoreNonDeducedTemplateTypes);
+ Options.store(Opts, "MoveFunction", MoveFunction);
}
} // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
index d8c3d2bd4ba0e..950c0206745d7 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
@@ -32,6 +32,7 @@ class RvalueReferenceParamNotMovedCheck : public ClangTidyCheck {
const bool AllowPartialMove;
const bool IgnoreUnnamedParams;
const bool IgnoreNonDeducedTemplateTypes;
+ const StringRef MoveFunction;
};
} // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 579fca54924d5..82f3bc038c2f2 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -219,6 +219,11 @@ Changes in existing checks
tolerating fix-it breaking compilation when functions is used as pointers
to avoid matching usage of functions within the current compilation unit.
+- Improved :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
+ <clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved>` check
+ by adding a flag to specify the function used for moving instead of
+ ``std::move``.
+
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
index ffa3a9d61e48e..aa2bed9e888a4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
@@ -79,6 +79,11 @@ Options
T other = std::forward<T>(t);
}
+.. option:: MoveFunction
+
+ Specify the function used for moving.
+ Default is `::std::move`.
+
This check implements `F.18
<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f18-for-will-move-from-parameters-pass-by-x-and-stdmove-the-parameter>`_
from the C++ Core Guidelines.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep alphabetical order (by check name) in this list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
please add [clang-tidy] and check name in PR title to avoid misunderstand
with :: means is a full name including namespace, without :: means only match function name. |
Since std::move is nothing more than a cast, part of STL and not the language itself, it's easy to provide a custom implementation if one wishes not to include the entirety of <utility>. Added flag (MoveFunction) provides a way to continue using this essential check even with the custom implementation of moving.
9a82260 to
07873f2
Compare
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
Outdated
Show resolved
Hide resolved
…lue-reference-param-not-moved.rst Co-authored-by: EugeneZelenko <[email protected]>
|
Please fix merge conflicts that occurred after merge of |
|
@DimitrijeDobrota Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Since std::move is nothing more than a cast, part of STL and not the language itself, it's easy to provide a custom implementation if one wishes not to include the entirety of .
Added flag (MoveFunction) provides a way to continue using this essential check even with the custom implementation of moving.
Since
::are specified beforestd::move, I am not entirely sure whether it would be required for the custom function. In my testing it worked both with and without::.